/*************************************************************************
 * @file: halfedge.cpp
 * @date: 01/04/2012
 * TOPOL v1_0 - (c)copyright 2012 TEC/UFF
 *************************************************************************
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 ************************************************************************/

// includes
//----------
#include "halfedge.h"
#include "edge.h"
#include <iostream>


///////////////////////////////////////////////////
///  Constructor and Destructor Implementation  ///
///////////////////////////////////////////////////

//-------------------------------------------------------------------------
HalfEdge::HalfEdge()
: m_prv( NULL )
, m_nxt( NULL )
, m_edg( NULL )
, m_vtx( NULL )
, m_wloop( NULL )
{

}
//-------------------------------------------------------------------------



///////////////////////////////////////
///  PUBLIC Methods Implementation  ///
///////////////////////////////////////

//-------------------------------------------------------------------------
HalfEdge* 
HalfEdge::delhe()
{
  if(this->m_edg == NULL)
  {
    //del(HALFEDGE, this, NULL);
    return(NULL);
  }
  else if(this->m_nxt == this)
  {
    this->m_edg = NULL;
    return(this);
  }
  else
  {
    this->m_prv->m_nxt = this->m_nxt;
    this->m_nxt->m_prv = this->m_prv;
    //del(HALFEDGE, this, NULL);
    return(this->m_prv);
  }
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
HalfEdge* 
HalfEdge::getPrv()
{
	return m_prv;
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
HalfEdge* 
HalfEdge::getNxt()
{
	return m_nxt;
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
Loop* 
HalfEdge::getLoop()
{
	return m_wloop;
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
Edge* 
HalfEdge::getEdg()
{
	return m_edg;
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
Vertex* 
HalfEdge::getVtx()
{
	return m_vtx;
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
HalfEdge* 
HalfEdge::mate()
{
  if( this->m_edg == NULL )
    return this;

  if( this == this->m_edg->getHe1() )
  {
    return this->m_edg->getHe2();
  }
  else
  {
    return this->m_edg->getHe1();
  }
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
void 
HalfEdge::setPrv( HalfEdge* _he )
{
  m_prv = _he;
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
void 
HalfEdge::setNxt( HalfEdge* _he )
{
  m_nxt = _he;
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
void 
HalfEdge::setWloop( Loop* _loop )
{
  m_wloop = _loop;
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
void 
HalfEdge::setEdg( Edge* _edge )
{
  m_edg = _edge;
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
void 
HalfEdge::setVtx( Vertex* _vertex )
{
  m_vtx = _vertex;
}
//-------------------------------------------------------------------------

